package com.extension.company.view.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.extension.company.admin.R;
import com.extension.company.model.entity.MyCollectionData;
import com.extension.company.common.widget.ShapedImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 我的收藏适配器
 * // BaseRecyclerAdapter<MyCollectionData, MyCollectionAdapter.Holder>
 */
public class MyCollectionAdapter extends RecyclerView.Adapter<MyCollectionAdapter.Holder> {


	private OnDeleteClickLister mDeleteClickListener;
	private Context context;
	private List<MyCollectionData> list;

	public MyCollectionAdapter(Context context, List<MyCollectionData> list) {
		this.context = context;
		this.list = list;
	}


	@NonNull
	@Override
	public Holder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
		View view = LayoutInflater.from(context).inflate(R.layout.mycollection_item, viewGroup, false);
		Holder holder = new Holder(view);
		return holder;
	}

	@Override
	public void onBindViewHolder(@NonNull final Holder holder, final int i) {
		holder.tvDelete.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				mDeleteClickListener.onDeleteClick(view, i);
			}
		});

	}

	@Override
	public int getItemCount() {
		return list.size();
	}


	class Holder extends RecyclerView.ViewHolder {
		@BindView(R.id.iv_photo)
		ShapedImageView ivPhoto;
		@BindView(R.id.tv_delete)
		TextView tvDelete;

		public Holder(@NonNull View itemView) {
			super(itemView);
			ButterKnife.bind(this, itemView);

		}
	}

	/**
	 * 点击删除
	 *
	 * @param listener
	 */
	public void setOnDeleteClickListener(OnDeleteClickLister listener) {
		this.mDeleteClickListener = listener;
	}

	public interface OnDeleteClickLister {
		void onDeleteClick(View view, int position);
	}
}
